package com.swz.dcrm.ui.home;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.swz.dcrm.adpter.FragmentViewPagerAdapter;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;
import com.swz.dcrm.util.Constant;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class CustomerManagementFragment extends BaseFragment {

    @BindView(R.id.toolbar_title)
    TextView title;
    @BindView(R.id.tab)
    SlidingTabLayout slidingTabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.tv_right)
    TextView tvRight;
    private String[] titles;
    private List<Fragment>fragments;


    public static CustomerManagementFragment newInstance() {

        return new CustomerManagementFragment();
        // Required empty public constructor
    }
    @Override
    public void onLoadRetry() {

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        onLoadRetry();
    }
    @Override
    public int layoutId() {
        return R.layout.fragment_customer_managerment;
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        fragments=new ArrayList<>();
        title.setText(getString(R.string.customer_management_title));
        titles=getResources().getStringArray(R.array.customer_management_state);
        for(int i=0;i<titles.length;i++){
            fragments.add(CustomerManagementItemFragment.newInstance(titles[i]));
        }
        tvRight.setText(getString(R.string.customer_management_add));
        viewPager.setAdapter(new FragmentViewPagerAdapter(getChildFragmentManager(),fragments, Arrays.asList(titles)));
        slidingTabLayout.setViewPager(viewPager);
        return true;
    }


    @OnClick(R.id.iv_back)
    public void backClick() {
        NavHostFragment.findNavController(this).navigateUp();
    }
    @OnClick(R.id.tv_right)
    public void right(){
        go(null,R.id.action_customerManagementFragment_to_addCustomerFragment,null);
    }
}
